/**
 * 
 */
package com.application.Adapter;

import com.application.Activity.R;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;


/**
 * @author TAI
 *
 */
public class FormUserListArrayAdapter extends ArrayAdapter<String> {
	private final Activity context;
	private final String[] names;
	private final String[] id;
	
	//Constructor
	public FormUserListArrayAdapter(Activity context, String[] names,String[] id){
		super(context, R.layout.listuser,names);
		this.context = context;
		this.names=names;
		this.id=id;
	}
	
	@Override
	public void add(String object) {
		// TODO Auto-generated method stub
		super.add(object);
		//this.names = object;
		
	}
	//phuong thuc tinh de luu tham chieu den cac loop ben ngaoi
	//va tranh truy cap den bat ky thanh phan nao co chua class
	//Lop trung gian lưu user list
	static class ViewUserList{
		public ImageView imageView;
		public TextView view_name;
		public TextView view_id;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		// ViewHolder will buffer the assess to the individual fields of the row
		// layout

		ViewUserList holder;
		// Recycle existing view if passed as parameter
		// This will save memory and time on Android
		// This only works if the base layout for all classes are the same
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.listuser, null, true);
			holder = new ViewUserList();
			holder.view_name = (TextView) rowView.findViewById(R.id.listuser_name);
			holder.view_id = (TextView) rowView.findViewById(R.id.listuser_id);
			holder.imageView = (ImageView) rowView.findViewById(R.id.listuser_img);
			rowView.setTag(holder);
		} else {
			holder = (ViewUserList) rowView.getTag();
		}

		holder.view_name.setText(names[position]);
		holder.view_id.setText(id[position]);
		// Change the icon for Windows and iPhone
		String s = names[position];
		//if (s.startsWith("Windows7") || s.startsWith("iPhone")
			//	|| s.startsWith("Solaris")) {
		if (position %2 ==0) {

			holder.imageView.setImageResource(R.drawable.img_user);
		} else {
			holder.imageView.setImageResource(R.drawable.img_user2);
		}

		return rowView;
		
	}

}
